package com.peoit.honeycomb.rest;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.peoit.honeycomb.application.FinanceReportApplication;
import com.peoit.honeycomb.domain.exception.ProjectNotExistException;
import com.peoit.honeycomb.domain.exception.ReportDateExistException;
import com.peoit.honeycomb.dto.CommonResultDto;
import com.peoit.honeycomb.dto.FinanceReportDto;

/**
 * 项目财务报表接口
 * 
 * @author shisheng.zheng
 *
 */
@Controller
@RequestMapping("/api/finance")
public class FinanceReportResource extends BaseResource {
	@Autowired
	FinanceReportApplication financeReportApplication;

	@RequestMapping(value = "/publishreport", method = RequestMethod.POST)
	public @ResponseBody CommonResultDto publishReport(FinanceReportDto dto) {
		CommonResultDto result = new CommonResultDto();
		try {
			financeReportApplication.publishReport(dto);
			result.setReason("success");
			result.setResult_code("200");
		} catch (ProjectNotExistException e) {
			result.setReason("project not exist");
			result.setResult_code("401");
		} catch (ReportDateExistException e) {
			result.setReason("reportDate is exists");
			result.setResult_code("403");
		} catch (Exception e) {
			result.setReason("Inter error");
			result.setResult_code("500");
		}
		return result;
	}

	/**
	 * 获取项目报表
	 * 
	 * @param projectId
	 *            项目ID
	 * @return
	 */
	@RequestMapping(value = "/listreport", method = RequestMethod.POST)
	public @ResponseBody CommonResultDto listReport(String projectId) {
		CommonResultDto result = new CommonResultDto();
		List<FinanceReportDto> dtos = financeReportApplication.getProjectFinanceReport(projectId);
		result.setResult(dtos);
		result.setReason("success");
		result.setResult_code("200");
		return result;
	}
}
